package com.aidex.biz.service.impl;

import java.util.Collections;
import java.util.List;

import com.aidex.biz.service.JinjianCodeService;
import com.aidex.biz.service.LoanBillService;
import com.aidex.common.annotation.DataScope;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.domain.entity.SysUser;
import com.aidex.common.core.domain.entity.SysDept;
import com.aidex.common.core.service.BaseServiceImpl;
import com.aidex.framework.cache.DeptUtils;
import com.aidex.framework.cache.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.aidex.biz.mapper.LoanBillDetailMapper;
import com.aidex.biz.domain.LoanBillDetail;
import com.aidex.biz.service.LoanBillDetailService;
import org.springframework.transaction.annotation.Transactional;
import com.aidex.common.utils.NumberUtils;

/**
 * 还款信息明细Service业务层处理
 *
 * @author sean
 * @email 2074844820@qq.com
 * @date 2025-07-03
 */
@Service
@Transactional(readOnly = true)
public class LoanBillDetailServiceImpl extends BaseServiceImpl<LoanBillDetailMapper, LoanBillDetail> implements LoanBillDetailService {
    private static final Logger log = LoggerFactory.getLogger(LoanBillDetailServiceImpl.class);


    @Autowired
    private LoanBillService loanBillService;

    /**
     * 获取单条数据
     *
     * @param loanBillDetail 还款信息明细
     * @return 还款信息明细
     */
    @Override
    public LoanBillDetail get(LoanBillDetail loanBillDetail) {
        LoanBillDetail dto = super.get(loanBillDetail);
        return dto;
    }

    /**
     * 获取单条数据
     *
     * @param id 还款信息明细id
     * @return 还款信息明细
     */
    @Override
    public LoanBillDetail get(String id) {
        LoanBillDetail dto = super.get(id);
        return dto;
    }


    /**
     * 查询还款信息明细列表
     *
     * @param loanBillDetail 还款信息明细
     * @return 还款信息明细
     */
    @Override
    @DataScope(userAlias = "a", deptAlias = "a")
    public List<LoanBillDetail> findList(LoanBillDetail loanBillDetail) {
        return super.findList(loanBillDetail);
    }

    /**
     * 分页查询还款信息明细列表
     *
     * @param loanBillDetail 还款信息明细
     * @return 还款信息明细
     */
    @Override
    @DataScope(userAlias = "a", deptAlias = "a")
    public PageInfo<LoanBillDetail> findPage(LoanBillDetail loanBillDetail) {
        return super.findPage(loanBillDetail);
    }

    /**
     * 保存还款信息明细
     *
     * @param loanBillDetail
     * @return 结果
     */
    @Override
    public boolean save(LoanBillDetail loanBillDetail) {
        return super.save(loanBillDetail);
    }


    /**
     * 删除还款信息明细信息
     *
     * @param loanBillDetail
     * @return 结果
     */
    @Override
    public boolean remove(LoanBillDetail loanBillDetail) {
        return super.remove(loanBillDetail);
    }

    /**
     * 批量删除还款信息明细
     *
     * @param ids 需要删除的还款信息明细ID
     * @return 结果
     */
    @Transactional(readOnly = false)
    @Override
    public int deleteLoanBillDetailByIds(String[] ids) {
        return mapper.deleteLoanBillDetailByIds(ids);
    }

    /**
     * 获取最大编号
     *
     * @param loanBillDetail 还款信息明细
     * @return 结果
     */
    @Override
    public int findMaxSort(LoanBillDetail loanBillDetail) {
        return NumberUtils.nextOrder(mapper.findMaxSort(loanBillDetail));
    }

    @Override
    public Integer insertBatch(List<LoanBillDetail> list) {
        return mapper.insertBatch(list);
    }

    @Override
    public boolean updateLoanBillDetailOverDue(LoanBillDetail loanBillDetail) {
        this.save(loanBillDetail);
        loanBillService.updateOverDue(loanBillDetail.getLoanId());
        return true;
    }

    @Override
    public List<LoanBillDetail> findListByLoanId(String loanId) {
        return mapper.findListByLoanId(loanId);
    }
}
